
from selenium.webdriver.common.by import By

from base.page_base import BasePage
from config import BASE_URL


class Login(BasePage):
    """登录页面封装"""

    # 定义登录url
    __login_url = BASE_URL + "/common/member/login"
    # 类属性:元素定位
    __phone = (By.ID, "keywords")
    __password = (By.ID, "password")
    __login_btn = (By.ID, "login-btn")

    # 登录成功文本元素
    __success_text = (By.CLASS_NAME, "a-link1")
    # 登录失败文本元素
    __fail_text = (By.CSS_SELECTOR, "span.ng-binding")

    def open_url(self):
        """打开登录页面"""
        self.driver.get(self.__login_url)

    def input_phone(self, phone):
        """输入手机号"""
        self.base_input(self.__phone, phone)

    def input_password(self, password):
        """输入密码"""
        self.base_input(self.__password, password)

    def click_login_btn(self):
        """点击登录按钮"""
        self.base_click(self.__login_btn)

    def get_result_success_text(self):
        """获取登录成功文本"""
        return self.fd_element(self.__success_text).text

    def get_result_fail_text(self):
        """获取登录失败文本"""
        return self.fd_element(self.__fail_text).text

    def login(self, phone, password="123456a"):
        """登录操作"""
        self.input_phone(phone)
        self.input_password(password)
        self.click_login_btn()
